@extends('admin.layout.base')
@section('title', '添加广告')
@section('pluginstyle')
<link rel="stylesheet" type="text/css" href="{{ asset('/plugins/webuploader/webuploader.css') }}">
<link rel="stylesheet" type="text/css" href="{{ asset('/dist/admin/plugins/datepicker/datepicker3.css') }}">
@endsection
@section('content')
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            添加广告
        </h1>
        <ol class="breadcrumb">
            <li><a href="{{ url('/admin') }}"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li><a href="{{ url('/admin/ads') }}">广告管理</a></li>
            <li class="active">添加广告</li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <!-- right column -->
            <div class="col-md-12">
                <!-- Horizontal Form -->
                <div class="box box-info">
                    <div class="box-header with-border">
                        <h3 class="box-title">添加广告</h3>
                    </div>
                    <!-- /.box-header -->
                    @if(session('error'))
                    <div class="alert alert-danger alert-dismissible">
                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                        {{ $error }}
                    </div>
                    @endif
                    <form class="form-horizontal" action="{{ url('/admin/ads') }}" method="post" enctype="multipart/form-data">
                        {!! csrf_field() !!}
                        <div class="box-body">
                            <div class="form-group">
                                <label for="ads_title" class="col-sm-2 control-label">广告标题</label>
                                <div class="col-sm-5">
                                    <input type="text" class="form-control" id="ads_title" name="ads_title" value="{{ old('ads_title') }}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="ads_position" class="col-sm-2 control-label">所属分类</label>
                                <div class="col-sm-5">
                                    <select name="ads_position" id="ads_position" class="form-control">
                                        <option value="">-- 请选择 --</option>
                                        @foreach($position as $key => $p)
                                        <option value="{{ $key }}">{{ $p }}</option>
                                        @endforeach
                                        </optgroup>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="ads_img" class="col-sm-2 control-label">广告图片</label>
                                <div class="col-sm-5">
                                    <div id="ads">选择图片</div>
                                    <img src="{{ old('ads_img') }}" alt="" class="img-thumbnail" />
                                    <input type="hidden" class="form-control" id="ads_img" name="ads_img" value="{{ old('ads_img') }}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="ads_url" class="col-sm-2 control-label">广告链接</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" id="ads_url" name="ads_url" value="{{ old('ads_url', '#') }}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="ads_starttime" class="col-sm-2 control-label">开始时间</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" id="ads_starttime" name="ads_starttime" value="{{ old('ads_starttime', date('Y-m-d')) }}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="ads_endtime" class="col-sm-2 control-label">结束时间</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" id="ads_endtime" name="ads_endtime" value="{{ old('ads_endtime', date('Y-m-d',strtotime('+1 Day'))) }}">
                                </div>
                            </div>
                            <button type="button" class="btn btn-default" onclick="history.go(-1)">返回</button>
                            <button type="submit" class="btn btn-info pull-right">添加</button>
                        </div>
                    </form>
                    <!-- form start -->
                </div>
                <!-- /.box -->
            </div>
            <!--/.col (right) -->
        </div>
        <!-- /.row -->
    </section>
    <!-- /.content -->
</div>
@endsection
@section('pluginscript')
<!-- FastClick -->
<script src="{{ asset('/dist/admin/plugins/fastclick/fastclick.js') }}"></script>
<script src="{{ asset('/dist/admin/plugins/datepicker/bootstrap-datepicker.js') }}"></script>
<script type="text/javascript" src="{{ asset('/plugins/webuploader/webuploader.js') }}"></script>
<script type="text/javascript" src="{{ asset('/common/js/upload.js') }}"></script>
<script type="text/javascript">
$(function() {
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });
    uploadone('#ads', "{{ url('/admin/ads/upload') }}");
    var datepickerParam = {
        autoclose:true,
        format:'yyyy-mm-dd'
    };
    $('#ads_starttime').datepicker(datepickerParam);
    $('#ads_endtime').datepicker(datepickerParam);
});
</script>
@endsection